{#
@author David Alexa <alexa.david@me.com>

Copyright (C) 2012-2015 CESNET

LICENSE TERMS

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in
  the documentation and/or other materials provided with the
  distribution.
3. Neither the name of the Company nor the names of its contributors
  may be used to endorse or promote products derived from this
  software without specific prior written permission.

ALTERNATIVELY, provided that this notice is retained in full, this
product may be distributed under the terms of the GNU General Public
License (GPL) version 2 or later, in which case the provisions
of the GPL apply INSTEAD OF those given above.

This software is provided ``as is'', and any express or implied
warranties, including, but not limited to, the implied warranties of
merchantability and fitness for a particular purpose are disclaimed.
In no event shall the company or contributors be liable for any
direct, indirect, incidental, special, exemplary, or consequential
damages (including, but not limited to, procurement of substitute
goods or services; loss of use, data, or profits; or business
interruption) however caused and on any theory of liability, whether
in contract, strict liability, or tort (including negligence or
otherwise) arising in any way out of the use of this software, even
if advised of the possibility of such damage.
#}

{% extends 'FITModuleDefaultBundle::layout.html.twig' %}
{% block title %}Section {% if sectionName is defined and not(sectionName is empty) %}- {{sectionName}}{% endif %}{% endblock title %}

{% set stateDefined = 'false' %}

{% block htmlAdditions %} ng-app="NetopeerGUIApp"{% endblock %}
{#{% block singlecontentAdditions %} ng-controller="ConfigurationController"{% endblock %}#}

{% block topMenu %}
	{% if not isSingleInstance %}
		<a href="{{ path('connections') }}" title="Home" class="static ico-home header-icon {% if activeAction is defined and activeAction == "home" %}active{% endif %}" data-callback="setIndexActions()"><span></span>Connections</a>
	{% endif %}
	{% if app.request.get('key') is defined and not (app.request.get('key') is empty) and lockedConn is defined %}
		{% if lockedConn == false %}
			<a href="{{ path("handleConnection", {"command": "lock", "key": app.request.get('key')} ) }}" title="Lock" class="static ico-unlock header-icon" data-disable-history="true" data-do-not-activate="true"><span></span></a>
		{% else %}
			<a href="{{ path("handleConnection", {"command": "unlock", "key": app.request.get('key')} ) }}" title="Unlock" class="static ico-lock header-icon" data-disable-history="true" data-do-not-activate="true"><span></span></a>
		{% endif %}
		<a href="#/action/session" title="Session info" class="static ico-session header-icon"><span></span></a>
		<a href="#/{{ path("handleBackup", {"key": app.request.get('key')}) }}" title="Backup connection" class="static ico-download header-icon"><span></span></a>
		<a href="{{ path("reloadDevice", {"key": app.request.get('key')}) }}" title="Refresh data" class="ico-refresh header-icon ajaxLink" data-do-not-activate="true" data-disable-history="true"><span></span></a>
		{% if topmenu is defined %}
			{% set i = 0 %}
			{% for section in topmenu %}
				<a href="#/module/{{ section.params.module }}" title="{{section.title}} ({{section.namespace}})" class="dynamic  nth-{{i}} {% if i == 0 %}active{% endif %}">{{section.name}}<span class="arrow"></span></a>
				{% set i = i + 1 %}
			{% endfor %}
			<a href="#/module/all" class="dynamic" title="GET all information">All<span class="arrow"></span></a>
			<a href="#/module/add-new-module" class="dynamic title="Insert into empty datastore">+<span class="arrow"></span></a>
		{% endif %}
	{% endif %}

	<div id="alerts-icon" class="static">
		<a href="" title="Show alerts" class="static header-icon ico-alerts"><span></span><strong class="count">0</strong></a>
	</div>

	{% if app.request.get('key') is defined and not (app.request.get('key') is empty) and
	not isSingleInstance %}
		<a href='{{ path("handleConnection", {"command": "disconnect", "key": app.request.get('key')} ) }}' class="static disconnect" data-disable-history="true" title="Disconnect from device">Disconnect</a>
	{% endif %}

	<div id="userpane" class="static dropdown">
		<a data-toggle="dropdown"><strong>{{ app.user.username|default(app.user) }}</strong> <span class="caret"></span></a>
		<ul class="dropdown-menu" role="menu" aria-labelledby="uLabel">
			{% if is_granted('IS_AUTHENTICATED_FULLY') %}
				<li><a href="{% if app.user.getTargetedID is defined %}{{ path('aerial_ship_saml_sp.security.logout') }}{% else %}{{ path('_logout') }}{% endif %}" class="log-out">Log out</a>
				</li>
			{% endif %}
		</ul>
	</div>

	<div class="others-cover">
		<div class="show-link header-icon ico-arrow-down">
			<span></span>
			<div class="others"></div>
		</div>
	</div>
{% endblock topMenu %}

{% block leftSubsection %}
	{% for subsection in submenu %}
		<a href="#/module/{{ subsection.params.module }}/{{ subsection.params.subsection }}" title="{{subsection.title}}" class="{% if subsectionName is defined and subsectionName == subsection.name %}active{% endif %}">{{subsection.name}}</a>
	{% endfor %}
{% endblock leftSubsection %}

{% block state %}
{% block singleContent %}
	<script type="text/javascript">
		var jsonEditable = {% if jsonEditable is defined and jsonEditable == false %}false{% else %}true{% endif %};
	</script>
	<div id="mainView" ng-view></div>
{% endblock singleContent %}
{% endblock state %}

{% block notifications %}
	{% if ncFeatures is defined and ncFeatures["nc_feature_notification"] is defined %}
		{% if (app.request.get('key') is defined) and (not (app.request.get('key') is empty)) and (lockedConn is defined) %}
			<script type="text/javascript">
				var lookupIpUrl = '{{ path('lookupIp', {"ip": "REPLACE_IP"}) }}';
				var socket = getNotifWebSocket({{ app.request.get('key') }}, "{% if sessionHash is defined %}{{sessionHash}}{% endif %}", "wss://{{ app.request.host }}:8080/");

				window.onbeforeunload = function() {
					socket.websocket.close();
				};
				if ($(notifOutput).hasClass('hidden')) {
					$(notifOutput).removeClass('hidden');
					notifResizable();
				}
			</script>
		{% endif %}
		<div class="notif-cover">
			<div class="notif-history-cover"></div>
			{#<a href="{{ path("notificationsHistoryTo", {"connectedDeviceId": app.request.get('key'), "from": '-10', 'to': '0'} ) }}" data-key="{{ app.request.get('key') }}" class="button grey right" id="js-get-notif-history" title="Get notifications from history">Load history</a>#}
			{# TODO: show, when notifications history wont cause deadlock #}
		</div>
	{% endif %}

{% endblock notifications %}

